﻿#region File Description
/****************************************************************************
*                                                                           *
* Game Manager.                                                             *
*                                                                           *
* Copyright (c) Ionescu Marius. All rights reserved(2013).                  *
*                                                                           *
****************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;
using Silverlight3D;

namespace sGaming
{
    public partial class MainPage : UserControl
    {
        private Scene scene;
        private Projector projector;
        private IShader shader;

        private Cube cube;

        public MainPage()
        {
            InitializeComponent();

            this.scene = new Scene();

            this.projector = new Projector();
            this.projector.ViewPosition = new Vector(0, 0, -40);
            this.projector.ViewFarDistance = 1000;
            this.projector.Zoom = 5000;
            this.projector.LightSourcePosition = new Vector(-100, -200, -200);
            this.projector.Origin = new Point(500, 280);

            this.shader = new Shader();

            this.cube = new Cube(new Vector(0, -10, 100), 50, "silverlight.png");

            // Causes Redraw() to be called on every frame. 
            CompositionTarget.Rendering += Redraw;
        }

        /// <summary> 
        /// Is called on every frame.  Updates and redraws everything. 
        /// </summary> 
        private void Redraw(object sender, EventArgs e)
        {
            // Add some random angles to these to give rotation 
            this.projector.RxTheta += 0.015;
            this.projector.RyTheta += 0.0235;
            this.projector.RzTheta += 0.0065;

            // Add the Cube to the Scene 
            this.scene.Clear();
            this.cube.AddToSceneWithImageSides(this.scene);

            // Clear the Canvas and redraw the Scene 
            this.Canvas.Children.Clear();

            this.scene.Draw(this.projector, this.Canvas, this.shader, this.cube.center);
        }
    }
}
